﻿using PMSystem.DataAccess;
using PMSystem.DataAccess.DataRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMSystem.ApplicationLogics
{
    public class AuditService
    {
        public void CreateAuditEntry(Audit audit)
        {
            try
            {
                if (audit != null)
                    using (var repo = new AuditRepository())
                    {
                        repo.InsertOrUpdate(audit);
                        repo.Save();
                    }
            }
            catch (Exception ex)
            {
                var errr = ex.Message;
            }
           
        }

        public List<Audit> GetAuditsBySearch(string keyword)
        {
            List<Audit> results = new List<Audit>();
            using (var repo = new AuditRepository())
            {
                results = repo.GetAll.ToList();
            }
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                results = results.Where(x =>
                    x.AuditType.ToLower().Contains(keyword.ToLower())
                    ||
                    x.AuditSummary.ToLower().Contains(keyword.ToLower())                  
                    ).ToList();
            }

            return results;
        }

    }
}
